﻿using System;
using Autofac;
using Hyt.Core;
using Hyt.Passport.Repositories;

namespace Hyt.Passport
{
    public abstract class IocSetting : IIocSetting
    {
        public void Register(ContainerBuilder builder, IUnitOfWork unitOfWork)
        {
            RegisterIAdministratorRepository(builder);
            RegisterIDepartmentRepository(builder);
            RegisterIOperationRepository(builder);
            RegisterIPositionRepository(builder);
        }

        /// <summary>
        /// 注册AdministratorRepository
        /// </summary>
        /// <param name="builder"></param>
        public virtual void RegisterIAdministratorRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetAdministratorRepository()).As<IAdministratorRepository>().PropertiesAutowired();
        }

        /// <summary>
        /// AdministratorRepository
        /// </summary>
        /// <returns></returns>
        public abstract Type GetAdministratorRepository();

        /// <summary>
        /// 注册DepartmentRepository
        /// </summary>
        /// <param name="builder"></param>
        public virtual void RegisterIDepartmentRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetDepartmentRepository()).As<IDepartmentRepository>().PropertiesAutowired();
        }

        /// <summary>
        /// DepartmentRepository
        /// </summary>
        /// <returns></returns>
        public abstract Type GetDepartmentRepository();

        /// <summary>
        /// 注册OperationRepository
        /// </summary>
        /// <param name="builder"></param>
        public virtual void RegisterIOperationRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetOperationRepository()).As<IOperationRepository>().PropertiesAutowired();
        }

        /// <summary>
        /// OperationRepository
        /// </summary>
        /// <returns></returns>
        public abstract Type GetOperationRepository();

        /// <summary>
        /// 注册PositionRepository
        /// </summary>
        /// <param name="builder"></param>
        public virtual void RegisterIPositionRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetPositionRepository()).As<IPositionRepository>().PropertiesAutowired();
        }

        /// <summary>
        /// PositionRepository
        /// </summary>
        /// <returns></returns>
        public abstract Type GetPositionRepository();

    }
}
